/**
 * Created by yangjiao on 2017/7/3.
 */
import callChannel from '../../../../api/config/channel/call-channel'
import call from '../../../../api/call'
import * as globalTypes from '../../../../mutation-types'
/**
 * 技能通话标签
 * @param {Object} data
 * @param {Number} [data.limit] 分页查询limit，默认10
 * @param {Number} [data.page] 分页查询page，默认1
 */
export const queryMultiCallLabels = ({commit, state, rootState, dispatch}, data) => {
  return callChannel.queryMultiCallLabels(data)
    .then(response => {
      return response
    })
    .catch(() => {
      commit(globalTypes.SET_ERROR, 'message.default_tips')
    })
}
/**
 * 保存通话标签
 * @param {Object} data
 * @param {Number} [data.limit] 分页查询limit，默认10
 * @param {Number} [data.page] 分页查询page，默认1
 */
export const saveMultiCallLabels = ({commit, state, rootState, dispatch}, data) => {
  return callChannel.saveMultiCallLabels(data)
    .then(response => {
      return response
    })
    .catch(() => {
      commit(globalTypes.SET_ERROR, 'message.default_tips')
    })
}
/**
 * 导入通话标签
 * @param data
 * @param data.batchNo 批次号
 * @param data.batchRemark 批次号说明
 * @param data.fileName  上传的文件id
 * @param data.trueName  上传的文件名
 * @returns {*}
 */
export const importCallLabel = ({commit, state, rootState, dispatch}, data) => {
  return callChannel.importCallLabel(data)
    .then(response => {
      return response
    })
    .catch(() => {
      commit(globalTypes.SET_ERROR, 'message.default_tips')
    })
}
export const queryCallLabelImportTask = ({commit, state, rootState, dispatch}, data) => {
  return callChannel.queryCallLabelImportTask(data)
    .then(response => {
      return response
    })
    .catch(() => {
      commit(globalTypes.SET_ERROR, 'message.default_tips')
    })
}
export const delCallLabelImportTask = ({commit, state, rootState, dispatch}, data) => {
  return callChannel.delCallLabelImportTask(data)
    .then(response => {
      return response
    })
    .catch(() => {
      commit(globalTypes.SET_ERROR, 'message.default_tips')
    })
}
export const batchUpdateCallLabelStatus = ({commit, state, rootState, dispatch}, data) => {
  return callChannel.batchUpdateCallLabelStatus(data)
    .then(response => {
      return response
    })
    .catch(() => {
      commit(globalTypes.SET_ERROR, 'message.default_tips')
    })
}

/**
 * 查询服务标签
 * @param {Object} data
 * @param {Number} [data.limit] 分页查询limit，默认10
 * @param {Number} [data.page] 分页查询page，默认1
 */
export const queryServiceQualityLabel = ({commit, state, rootState, dispatch}, data) => {
  return callChannel.queryServiceQualityLabel(data)
    .then(response => {
      return response
    })
    .catch(() => {
      commit(globalTypes.SET_ERROR, 'message.default_tips')
    })
}
/**
 * 保存服务标签
 * @param {Object} data
 */
export const saveServiceQualityLabel = ({commit, state, rootState, dispatch}, data) => {
  return callChannel.saveServiceQualityLabel(data)
    .then(response => {
      return response
    })
    .catch(() => {
      commit(globalTypes.SET_ERROR, 'message.default_tips')
    })
}
/**
 * 修改服务标签状态
 * @param {Object} data
 */
export const updateServiceQualityLabelStatus = ({commit, state, rootState, dispatch}, data) => {
  return callChannel.updateServiceQualityLabelStatus(data)
    .then(response => {
      return response
    })
    .catch(() => {
      commit(globalTypes.SET_ERROR, 'message.default_tips')
    })
}
/**
 * 保存满意度选项
 * @param {Object} data
 */
export const updateOneAppDic = ({commit, state, rootState, dispatch}, data) => {
  return callChannel.updateOneAppDic(data)
    .then(response => {
      // if (response.success) {
      return response
      // }
    })
    .catch(() => {
      commit(globalTypes.SET_ERROR, 'message.default_tips')
    })
}
/**
 * 查询满意度选项
 * @param {Object} data
 */
export const findOneAppDic = ({commit, state, rootState, dispatch}, data) => {
  return callChannel.findOneAppDic(data)
    .then(response => {
      // if (response.success) {
      return response
      // }
    })
    .catch(() => {
      commit(globalTypes.SET_ERROR, 'message.default_tips')
    })
}
// 删除录音库
export const deleteSound = ({commit, state, rootState, dispatch}, data) => {
  return callChannel.deleteSound(data)
    .then(response => {
      return response
    })
    .catch((error) => {
      console.log(error)
      commit(globalTypes.SET_ERROR, 'message.default_tips')
    })
}
// 查询录音库
export const querySound = ({commit, state, rootState, dispatch}, data) => {
  return callChannel.querySound(data)
    .then(response => {
      return response
    })
    .catch((error) => {
      console.log(error)
      commit(globalTypes.SET_ERROR, 'message.default_tips')
    })
}
// 查询黑红名单
export const queryBlackNum = ({commit, state, rootState, dispatch}, data) => {
  return callChannel.queryBlackNum(data)
    .then(response => {
      return response
    })
    .catch((error) => {
      console.log(error)
      commit(globalTypes.SET_ERROR, 'message.default_tips')
    })
}
// 删除黑红名单
export const delBlackNum = ({commit, state, rootState, dispatch}, data) => {
  return callChannel.delBlackNum(data)
    .then(response => {
      return response
    })
    .catch((error) => {
      console.log(error)
      commit(globalTypes.SET_ERROR, 'message.default_tips')
    })
}
// 保存黑红名单
export const saveBlackRedList = ({commit, state, rootState, dispatch}, data) => {
  console.log(222)
  return callChannel.saveBlackList(data)
    .then(response => {
      return response
    })
    .catch((error) => {
      console.log(error)
      commit(globalTypes.SET_ERROR, 'message.default_tips')
    })
}
 // 服务号start
// 查询服务号
export const queryServiceNo = ({commit, state, rootState, dispatch}, data) => {
  return callChannel.queryServiceNo(data)
    .then(response => {
      return response
    })
    .catch((error) => {
      console.log(error)
      commit(globalTypes.SET_ERROR, 'message.default_tips')
    })
}
// 添加服务号
export const saveServiceNo = ({commit, state, rootState, dispatch}, data) => {
  return callChannel.saveServiceNo(data)
    .then(response => {
      return response
    })
    .catch((error) => {
      console.log(error)
      commit(globalTypes.SET_ERROR, 'message.default_tips')
    })
}
// 添加轻量级服务号
export const saveLightServiceNo = ({commit, state, rootState, dispatch}, data) => {
  return callChannel.saveLightServiceNo(data)
    .then(response => {
      return response
    })
    .catch((error) => {
      console.log(error)
      commit(globalTypes.SET_ERROR, 'message.default_tips')
    })
}
// 修改服务号
export const updateServiceNo = ({commit, state, rootState, dispatch}, data) => {
  return callChannel.updateServiceNo(data)
    .then(response => {
      return response
    })
    .catch((error) => {
      console.log(error)
      commit(globalTypes.SET_ERROR, 'message.default_tips')
    })
}
// 删除服务号
export const deleteServiceNo = ({commit, state, rootState, dispatch}, data) => {
  return callChannel.deleteServiceNo(data)
    .then(response => {
      return response
    })
    .catch((error) => {
      console.log(error)
      commit(globalTypes.SET_ERROR, 'message.default_tips')
    })
}
// 服务号end
// 日程管理 start
// 查询日程
export const querySchedule = ({commit, state, rootState, dispatch}, data) => {
  return callChannel.querySchedule(data)
    .then(response => {
      return response
    })
    .catch((error) => {
      console.log(error)
      commit(globalTypes.SET_ERROR, 'message.default_tips')
    })
}
// 添加日程
export const saveSchedule = ({commit, state, rootState, dispatch}, data) => {
  return callChannel.saveSchedule(data)
    .then(response => {
      return response
    })
    .catch((error) => {
      console.log(error)
      commit(globalTypes.SET_ERROR, 'message.default_tips')
    })
}
// 修改日程
export const updateSchedule = ({commit, state, rootState, dispatch}, data) => {
  return callChannel.updateSchedule(data)
    .then(response => {
      return response
    })
    .catch((error) => {
      console.log(error)
      commit(globalTypes.SET_ERROR, 'message.default_tips')
    })
}
// 删除日程
export const deleteSchedule = ({commit, state, rootState, dispatch}, data) => {
  return callChannel.deleteSchedule(data)
    .then(response => {
      return response
    })
    .catch((error) => {
      console.log(error)
      commit(globalTypes.SET_ERROR, 'message.default_tips')
    })
}
// 日程管理 end
/**
 * ivr生效
 * @param {Object} data
 * @param {String} data.Account 账号id
 * @param {Array} data.PBX pbx数组
 */
export const reloadIvr = ({commit, state, rootState, dispatch}, data) => {
  return call.reloadIvr(data)
    .then(response => {
      return response
    })
    .catch((error) => {
      console.log(error)
      commit(globalTypes.SET_ERROR, 'message.default_tips')
    })
}
// 更新语音库
export const updateSound = ({commit, state, rootState, dispatch}, data) => {
  return callChannel.updateSound(data)
    .then(response => {
      return response
    })
    .catch((error) => {
      console.log(error)
      commit(globalTypes.SET_ERROR, 'message.default_tips')
    })
}
// 语音上传到七牛来转换成wav
export const soundToQiniuTransfer = ({commit, state, rootState, dispatch}, data) => {
  return callChannel.soundToQiniuTransfer(data)
    .then(response => {
      return response
    })
    .catch((error) => {
      console.log(error)
      commit(globalTypes.SET_ERROR, 'message.default_tips')
    })
}
// 再次尝试语音上传到七牛来转换成wav
export const soundToQiniuTransferRefresh = ({commit, state, rootState, dispatch}, data) => {
  return callChannel.soundToQiniuTransferRefresh(data)
    .then(response => {
      return response
    })
    .catch((error) => {
      console.log(error)
      commit(globalTypes.SET_ERROR, 'message.default_tips')
    })
}
// 获取流程配置的列表
export const queryIvrProcessList = ({commit, state, rootState, dispatch}, data) => {
  return callChannel.queryIvrProcessList(data)
    .then(response => {
      return response
    })
    .catch((error) => {
      console.log(error)
      commit(globalTypes.SET_ERROR, 'message.default_tips')
    })
}
// 删除流程
export const delIvrProcess = ({commit, state, rootState, dispatch}, data) => {
  return callChannel.delIvrProcess(data)
    .then(response => {
      return response
    })
    .catch((error) => {
      console.log(error)
      commit(globalTypes.SET_ERROR, 'message.default_tips')
    })
}
// 更新流程
export const updateIvrProcess = ({commit, state, rootState, dispatch}, data) => {
  return callChannel.updateIvrProcess(data)
    .then(response => {
      return response
    })
    .catch((error) => {
      console.log(error)
      commit(globalTypes.SET_ERROR, 'message.default_tips')
    })
}
// 保存流程
export const saveIvrProcess = ({commit, state, rootState, dispatch}, data) => {
  return callChannel.saveIvrProcess(data)
    .then(response => {
      return response
    })
    .catch((error) => {
      console.log(error)
      commit(globalTypes.SET_ERROR, 'message.default_tips')
    })
}
// 根据id获取流程图的数据
export const queryIvrProcessById = ({commit, state, rootState, dispatch}, data) => {
  return callChannel.queryIvrProcessById(data)
    .then(response => {
      return response
    })
    .catch((error) => {
      console.log(error)
      commit(globalTypes.SET_ERROR, 'message.default_tips')
    })
}
// 输入账号密码登录后可以更改通话配置
export const ivrOperationVerify = ({commit, state, rootState, dispatch}, data) => {
  return callChannel.ivrOperationVerify(data)
    .then(response => {
      return response
    })
    .catch((error) => {
      console.log(error)
      commit(globalTypes.SET_ERROR, 'message.default_tips')
    })
}
// 导入黑红名单  获取xls表头
export const getBlackRedXlsHeads = ({commit, state, rootState, dispatch}, data) => {
  return callChannel.getBlackRedXlsHeads(data)
    .then(response => {
      return response
    })
    .catch((error) => {
      console.log(error)
      commit(globalTypes.SET_ERROR, 'message.default_tips')
    })
}
// 导入黑红名单 写入
export const blackRedListImport = ({commit, state, rootState, dispatch}, data) => {
  return callChannel.blackRedImport(data)
    .then(response => {
      return response
    })
    .catch((error) => {
      console.log(error)
      commit(globalTypes.SET_ERROR, 'message.default_tips')
    })
}
// 查询导入黑红名单批次列表
export const queryBlackRedImportTasks = ({commit, state, rootState, dispatch}, data) => {
  return callChannel.queryBlackRedImportTasks(data)
    .then(response => {
      return response
    })
    .catch((error) => {
      console.log(error)
      commit(globalTypes.SET_ERROR, 'message.default_tips')
    })
}
// 查询导入黑红名单批次详情
export const queryImportDataDetail = ({commit, state, rootState, dispatch}, data) => {
  return callChannel.queryImportDataDetail(data)
    .then(response => {
      return response
    })
    .catch((error) => {
      console.log(error)
      commit(globalTypes.SET_ERROR, 'message.default_tips')
    })
}
// 批量删除黑红名单
export const batchDeleteBlackNumber = ({commit, state, rootState, dispatch}, data) => {
  return callChannel.batchDeleteBlackNumber(data)
    .then(response => {
      return response
    })
    .catch((error) => {
      console.log(error)
      commit(globalTypes.SET_ERROR, 'message.default_tips')
    })
}
// 查询电话本列表
export const queryCallBook = ({commit, state, rootState, dispatch}, data) => {
  return callChannel.queryCallBook(data)
    .then(response => {
      return response
    })
    .catch((error) => {
      console.log(error)
      commit(globalTypes.SET_ERROR, 'message.default_tips')
    })
}
// 新增电话本
export const addCallBook = ({commit, state, rootState, dispatch}, data) => {
  return callChannel.addCallBook(data)
    .then(response => {
      return response
    })
    .catch((error) => {
      console.log(error)
      commit(globalTypes.SET_ERROR, 'message.default_tips')
    })
}
// 编辑电话本
export const updateCallBook = ({commit, state, rootState, dispatch}, data) => {
  return callChannel.updateCallBook(data)
    .then(response => {
      return response
    })
    .catch((error) => {
      console.log(error)
      commit(globalTypes.SET_ERROR, 'message.default_tips')
    })
}
// 删除电话本
export const deleteCallBook = ({commit, state, rootState, dispatch}, data) => {
  return callChannel.deleteCallBook(data)
    .then(response => {
      return response
    })
    .catch((error) => {
      console.log(error)
      commit(globalTypes.SET_ERROR, 'message.default_tips')
    })
}
